#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django.urls import path, re_path, include
from . import views

app_name = "demo"

# 自动生成路由信息(和模型视图集一起使用)
from rest_framework.routers import DefaultRouter, SimpleRouter

# 1、实例化路由类
router = DefaultRouter()
# 2、给路由注册视图集
router.register("student8", views.StudentModelViewSet, basename="student8")  # 不能用正则
# 3、把生成的路由列表和urlpatterns进行拼接

urlpatterns = [
    # path('', include(router.urls)),
    path("students/", views.StudentApiView.as_view()),
    re_path("^students/(?P<pk>\d+)/$", views.StudentsInfoApiView.as_view()),
    # GenericApiView
    path("students2/", views.StudentGenericApiView.as_view()),
    re_path("^students2/(?P<pk>\d+)/$", views.StudentsInfoGenericApiView.as_view()),
    path("students3/", views.StudentMixinView.as_view()),
    re_path("^students3/(?P<pk>\d+)/$", views.StudentInfoMixinView.as_view()),
    # 视图子类使用
    path("students4/", views.StudentView.as_view()),
    re_path("^students4/(?P<pk>\d+)/$", views.StudentInfoView.as_view()),
    # 视图集
    path("students5/", views.StudentViewSet.as_view(
        {"get": "get_list", "post": "create_student"}
    )),
    re_path("^students5/(?P<pk>\d+)/$", views.StudentViewSet.as_view(
        {"get": "get_student_info", "put": "update_student", "delete": "delete_student"}
    )),

    # 通用视图集
    path("students6/", views.StudentGenericViewSet.as_view(
        {
            "get": "get_list",
            "post": "create_student"
        }
    )),
    re_path("^students6/(?P<pk>\d+)/$", views.StudentGenericViewSet.as_view(
        {
            "get": "get_student",
            "put": "update_student",
            "delete": "delete_student"
        }
    )),

    # path("student8/login/", views.StudentModelViewSet.as_view(
    #     {
    #         "get": "login",
    #     }
    # )),
]
urlpatterns += router.urls
